const fs = require('fs')
const path = require('path')
const upload = function (ctx) {
    const file = ctx.request.files.file // 获取上传文件
    const reader = fs.createReadStream(file.path);
    const fileName = `${new Date().getTime()}.jpg`
    let filePath = path.join(__dirname, '../static/img/') + `/${fileName}`;
    // 创建可写流
    const upStream = fs.createWriteStream(filePath);
    // 可读流通过管道写入可写流
    reader.pipe(upStream);
    return fileName
}

module.exports = upload